package cn.jiaqiang.chatgpt.data.infrastructure.repository;

import cn.jiaqiang.chatgpt.data.domain.openai.model.entity.UserModelEntity;
import cn.jiaqiang.chatgpt.data.domain.openai.repository.IUserModelRepository;
import cn.jiaqiang.chatgpt.data.infrastructure.dao.IUserModelDao;
import cn.jiaqiang.chatgpt.data.infrastructure.po.UserModelPO;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * User: jia-qiang
 * Date: 2024-04-09
 * Time: 22:58
 */
@Repository
public class UserModelRepository implements IUserModelRepository {

    @Resource
    private IUserModelDao userModelDao;

    /**
     * 查询额度
     * @param userId 用户id
     * @param model 模型
     */
    @Override
    public UserModelEntity queryUserModelEntityWithUserIdModel(Long userId, String model) {
        UserModelPO userModelPO = userModelDao.queryUserModelPOWithUserIdModel(userId, model);
        if (userModelPO == null) {
            return null;
        }
        return UserModelEntity
                .builder()
                .model(userModelPO.getModel())
                .userId(userModelPO.getUserId())
                .quota(userModelPO.getQuota())
                .build();
    }
}
